<script>
    initDialog("#app_result","Add new tab");
    
	function appointmentsMore(tid){
	    $("#app_result").load("<?= base_url(); ?>index.php?/more_info/appointmentsMoreInfo/"+tid);
	    openDialog('#app_result');
	}
</script>

<div id="appointmentsPage">
    <div class="post">
        <h2 class="title">Diary</h2>
        <div class="entry">
            <script>
                $(function() {
                    $( "#app_datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
                });
            </script>

            <input type="button" value="Add new" onclick="show('#new_app')"/>
            <?php
            //    if ($this->session->userdata("admin")) {
            ?>
            <input type="button" value="Search" onclick="show('#searchAppointments')"/>    
            <input type="button" value="Clear Search" onclick="clearSearch()"/>
            <?php
            //    }
            ?>
            <div id="view_result" class="info">
                <?= $message ?>
            </div>
            <script type="text/javascript">
                function searchAppointments(){
                    field=document.getElementById("searchAppointmentsForm").field.value;
                    search=document.getElementById("searchAppointmentsForm").search.value;
                    $("#appointmentsPage").load("<?= base_url(); ?>index.php?/admin_mis/appointments/"+field+"/"+search);
                }
                function clearSearch(){
                    $("#appointmentsPage").load("<?= base_url(); ?>index.php?/admin_mis/appointments/");
                }
            </script>

            <div id="app_result" style="display: none">
            </div>
            <!--a href="" id="hide3" >Hide</a> <a href="" id="show3" >Show</a-->
            <div id="new_app" style="display: none;margin-bottom: 10px;">
                <?php $data['id'] = "app_form" ?>
                <?= form_open_multipart('mis/saveAppointment', $data); ?>
                <table>
                    <tr class="darker"><td class="half">To where</td><td><input type="text" class="wide" name="to_where" value="<?php echo set_value('to_where'); ?>" /></td> </tr>
                    <tr class="lighter"><td>Person to see</td><td><input type="text" class="wide"  name="with" value="<?php echo set_value('with'); ?>" /></td> </tr>
                    <tr class="darker"><td>When</td><td><input type="text" class="wide"  name="when" value="<?php echo set_value('when'); ?>" id="app_datepicker" /></td> </tr>
                    <tr  class="lighter"><td>Accompanied by</td><td><input type="text"  class="wide" name="who" value="<?php echo set_value('who'); ?>" /></td> </tr>
                    <tr  class="darker"><td>Agenda</td><td><input type="text"  class="wide" name="agenda" value="<?php echo set_value('agenda'); ?>" /></td> </tr>
                    <tr><td colspan="2" style="text-align: right">
                            <input type="submit" value="Submit" />
                            <input type="button" value="Cancel" onclick="hide('#new_app')"/>
                        </td></tr>
                </table>
                </form>
            </div>


            <div id="searchAppointments" style="display: none;margin-bottom: 10px;">
                <form id="searchAppointmentsForm">
                    <table>
                        <tr class="darker"><td class="half">Select search criteria</td>
                            <td><select name="field">
                                    <option value='all' >All</option>
                                    <option value='with' >Appointment with</option>
                                    <option value='to_where' >Where</option>
                                    <option value='who' >Attended by</option>
                                    <option value='agenda' >Agenda</option>
                                    <option  value='added_by'> Added by</option>
                                </select></td>
                            <td><input type="text" name="search" class="wide"  value="<?php echo set_value('added_by'); ?>" /></td>
                        </tr>

                        <tr><td colspan="3" style="text-align: right">
                                <input type="button" value="Submit" onclick="searchAppointments()" />
                                <input type="button" value="Cancel" onclick="hide('#searchAppointments')"/>
                            </td></tr>

                    </table>
                </form>
            </div>
            <div id="all_app">
                <?= $tablet ?>
                <?= $pagina ?>
            </div>

        </div>
    </div>
</div>